package com.rxyb.security.exception;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.rxyb.core.respone.enums.CommonCode;
import lombok.SneakyThrows;

import java.io.IOException;

/**
 * @author YJH
 * @version 1.0
 * @description 序列化异常
 * @date 2020/5/22  15:01
 */
public class BusiOAuth2ExceptionJacksonSerializer extends StdSerializer<BusiOAuth2Exception> {

    protected BusiOAuth2ExceptionJacksonSerializer() {
        super(BusiOAuth2Exception.class);
    }

    @SneakyThrows
    @Override
    public void serialize(BusiOAuth2Exception value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeStartObject();
        gen.writeObjectField("code", CommonCode.FAILED.getCode());
        gen.writeStringField("msg", value.getMessage());
        gen.writeStringField("data", null);
        gen.writeEndObject();
    }
}
